package com.sprouting.personal.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sprouting.personal.dao.DynamicDataDetailedDao;
import com.sprouting.personal.dao.DynamicRecordingDao;
import com.sprouting.personal.model.entity.DynamicDataDetailed;
import com.sprouting.personal.model.entity.DynamicRecording;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * 动态记录表 主表
 *
 * @author ：LX（长沙麓谷）
 * @date 创建时间： 2023/1/30 10:37
 */
@Service
@Slf4j
public class DynamicRecordingService extends ServiceImpl<DynamicRecordingDao, DynamicRecording> {

    @Resource
    private DynamicRecordingDao dynamicRecordingDao;
    @Resource
    private DynamicDataDetailedDao dynamicDataDetailedDao;


    /**
     * 删除动态数据
     * @param id 动态数据主表ID
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public void delDynamicRecordingById(String id) {
        dynamicRecordingDao.deleteById(id);

        LambdaQueryWrapper<DynamicDataDetailed> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(DynamicDataDetailed::getDynamicId, id);
        dynamicDataDetailedDao.delete(wrapper);
    }

    /**
     * 分页查询动态数据表
     * @param page 分页参数
     * @param dynamicRecording 查询参数
     * @return
     */
    public Page<DynamicRecording> getDynamicRecordingListPage(Page page, DynamicRecording dynamicRecording) {
        return dynamicRecordingDao.getDynamicRecordingListPage(page, dynamicRecording);
    }

    /**
     * 根据主键查询动态表主表
     * @param id 主键
     * @return
     */
    public DynamicRecording getRecordingById(String id) {
        return dynamicRecordingDao.getRecordingById(id);
    }
}
